#pragma once

#include "TypeDefin.h"
#include "iostream"
#include "vector"
#include "algorithm"

using namespace std;
/*HJJ QQ479287006
 *给定一个已排序的链表的头 head ， 删除原始链表中所有重复数字的节点，只留下不同的数字 。返回 已排序的链表 。
输入：head = [1,1,1,2,3]
输出：[2,3]
 * */
//递归不会这个算无脑写的 30分估计也有
ListNode *deleteDuplicates(ListNode *head) {

    if (head == nullptr || head->next == nullptr)
        return head;
    ListNode *newHead = new ListNode;
    newHead->next = head;
    ListNode *pre = newHead;


    while (head && head->next) {

        if (head->val != head->next->val) {
            pre = head;
            head = head->next;
        } else {
            //如果值相同的话
            while (head && head->next && head->val == head->next->val) {
                head = head->next;
            }
            head = head->next;
            pre->next = head;

        }

    }


    return newHead->next;
}


//其实我觉得我递归应该想起来的 但是没做出来
ListNode *deleteDuplicates(ListNode *head) {
    if (!head || !head->next)
        return head;

    if (head->next && head->val == head->next->val) {
        while (head->next && head->val == head->next->val) {
            head = head->next;
        }
        //继续删除
        return deleteDuplicates(head->next);
    } else {
        head->next = deleteDuplicates(head->next);
    }

    return head;
}

